﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections;

namespace SCOSub
{
        public partial class ExportQMscript : Form
        {
                public ExportQMscript(string s, WorkMode wm)
                {
                        InitializeComponent();
                        workmode = wm;
                        source = s;
                        this.TopMost = Const.DoTopMost;

                }
                private IEffectModeBuildable ic;
                private WorkMode workmode;
                private string source;

                private void buildbutton_Click(object sender, EventArgs e)
                {
                        DialogResult dr = saveFileDialog1.ShowDialog();
                        if (dr != DialogResult.OK)
                                return;
                        switch (workmode)
                        {
                                case WorkMode.Effect: ic = new ChangeFormatEffects(); break;
                                case WorkMode.Time: break;
                                default: return;
                        }
                        double fps;
                        try
                        {
                                fps = double.Parse(textBox5.Text);
                        }
                        catch
                        {
                                MessageBox.Show("格式错误");
                                return;
                        }
                        string tlposX = textBox1.Text;
                        string tlposY = textBox2.Text;
                        string inposX = textBox3.Text;
                        string inposY = textBox4.Text;
                        string output = @"[General]
Description=AE添加ASS时间
BeginHotkey=121
BeginHotkeyMod=0
PauseHotkey=0
PauseHotkeyMod=0
StopHotkey=123
StopHotkeyMod=0
RunOnce=1
EnableWindow=
Enable=1
AutoRun=0
[Repeat]
Type=0
Number=1
[Relative]
SetupOCXFile=
[Comment]
Content=

[Script]
";

                        List<TimeAndText> list = ic.AddSourceText(source);
                        if (list.Count == 0)
                                return;

                        for (int i = 0; i < list.Count - 1; i++)
                        {
                                output += "MoveTo " + tlposX + "," + tlposY + "\r\n";
                                output += @"LeftClick 1
    KeyDown 17,1
    KeyDown 16,1
    KeyDown 18,1
    KeyPress 84,1
    KeyUp 18,1
    KeyUp 16,1
    KeyUp 17,1
";
                                output += "Delay 500\r\n";
                                output += "SayString " + list[i].Text + "\r\n";
                                output += "Delay 500\r\n";
                                output += "MoveTo " + inposX + "," + inposY + "\r\n";
                                output += "LeftClick 1\r\n";
                                output += "Delay 500\r\n";
                                output += "SayString " + "0;00;00;" + (int)((double)list[i].StartTime_MilliSecondFormat / 1000 * fps) + "\r\n";
                                output += "Delay 500\r\n";
                                output += "KeyPress 13,1\r\n";
                                output += "Delay 500\r\n";

                        }
                        
                        System.IO.StreamWriter sw = new System.IO.StreamWriter(saveFileDialog1.FileName, false, Encoding.Default);
                        sw.WriteLine(output);
                        sw.Close();
                        
                }
        }
}
